base = 'http://eq2.playhard.ru'

import urllib, urllib2

def get_url(url, file, try_num = 0):
    if try_num > 5:
        print "IOError while getting url %s" % url
        return None
    try:
        data = urllib2.urlopen(url)
        print "url %s found" % url
        return data.readlines()
    except urllib2.URLError:
        return get_url(url, try_num + 1)
    except urllib2.HTTPError:
        print "url %s not found" % url
        return None

def urlretrieve(url, file, try_count = 0):
    if try_count > 5:
        print "error on url %s" % url
    try:
        urllib.urlretrieve(url, file)
    except IOError:
        return urlretrieve(url, file, try_count + 1)
    except:
        return urlretrieve(url, file, try_count + 1)

def gather_quests():
    #return [get_url("%s/Quest.aspx?id=%d" % (base, num)) for num in xrange(10000)]
    [urlretrieve("%s/Zone.aspx?id=%d" % (base, num), "locations/%d" % num) for num in xrange(500)]


quests = gather_quests()
